package order.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import order.domain.Order;
import order.service.OrderService;
import com.feign.utils.R;
import order.vo.submitOrder.SubmitOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 订单(Order)表控制层
 *
 * @author panghu
 * @since 2023-03-04 21:06:48
 */
@RestController
@RequestMapping("order/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 查看订单列表
     *
     */
    @GetMapping("{page}/{limit}")
    public R orderList(@PathVariable Integer page, @PathVariable Integer limit,HttpServletRequest request) {
        Page<Map<String, Object>> orderPage = orderService.getOrderListWithPage(page, limit,request);
        return R.ok().setData(orderPage);
    }

    @PostMapping("submitOrder")
    public R submitOrder(@RequestBody SubmitOrderVo submitOrderVo, @RequestParam("tradeNo") String tradeNo, HttpServletRequest request) {
        return orderService.submitOrder(submitOrderVo, tradeNo, request);
    }

    @DeleteMapping("del/{orderId}")
    public R delete(@PathVariable Long orderId) {
        orderService.delOrderById(orderId);
        return R.ok("删除订单成功！");
    }

}

